package it.xiuxian.personcenter.activity

import android.view.View
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import it.xiuxian.lib.base.App
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.lib.utils.DensityUtil
import it.xiuxian.lib.utils.Subscribe
import it.xiuxian.lib.utils.adapter.SlimAdapter
import it.xiuxian.lib.utils.adapter.SlimInjector
import it.xiuxian.lib.utils.adapter.injector.IViewInjector
import it.xiuxian.personcenter.R
import it.xiuxian.personcenter.bean.DetailListBean
import it.xiuxian.personcenter.bean.MyDetail
import it.xiuxian.personcenter.bean.WalletDetailBean
import it.xiuxian.personcenter.databinding.ActivityMyWalletBinding
import it.xiuxian.personcenter.presenter.MyWalletActivityPresenter
import java.util.*

@Route(path = ArouterAddress.MYWALLETACTIVITY)
class MyWalletActivity:BaseActivity<MyWalletActivityPresenter>() {
   lateinit var binding:ActivityMyWalletBinding
    var adapter1: SlimAdapter?=null
    override val layoutId: Int
        get() = R.layout.activity_my_wallet
    override val presenter: MyWalletActivityPresenter
        get() = MyWalletActivityPresenter()

    override fun initData() {
        mPresenter!!.getRecord()
       // mPresenter!!.getDetail("1","3")
    }

    override fun initView() {
      binding =  getViewDataBinding<ActivityMyWalletBinding>()
        setTitle("钱包详情")
        binding.include.rightTv.text = "余额明细"
        binding.include.rightTv.visibility = View.VISIBLE
      //  binding.include.rightTv.setTextColor(getColor(R))
       /* binding.rv.layoutManager = LinearLayoutManager(this)
        (binding.include.re.layoutParams as LinearLayout.LayoutParams).setMargins(0,
            DensityUtil.getStatusPix(App.INSTANCE.applicationContext)+5,0,0)
        adapter1 = SlimAdapter.create().register<MyDetail>(R.layout.personcenter_detail_item,
            object: SlimInjector<MyDetail>{
                override fun onInject(
                    data: MyDetail?,
                    injector: IViewInjector<out IViewInjector<*>>?
                ) {

                    injector!!.text(R.id.tv_tou,data!!.leixingname)
                        .text(R.id.tv_time,data.createdate)
                        .text(R.id.tv_num,data.money)

                }
            }).attachTo(binding.rv)*/
    }

    override fun initEvent() {
        binding.include.rightTv.setOnClickListener {
            ARouter.getInstance().build(ArouterAddress.RECORDDETAILACTIVITY).navigation()
        }
       /* binding.smart.setOnRefreshListener {
            mPresenter!!.getDetail("1","3")
            binding.smart.finishRefresh()
        }
        binding.smart.setOnLoadMoreListener {
            mPresenter!!.getDetail(i++.toString(),"3")
        }*/
    }
    fun setGongXian(data: WalletDetailBean){
        //binding.tvGongxianzhi.text="贡献值:"+data.gongxianzhi
        binding.tvYue.text = "￥"+data.money
       // binding.tvTixianyue.text = "已提现余额:"+data.yitixianmoney
    }

var i=1

var newList = ArrayList<MyDetail>()
fun setData(data: DetailListBean){
    if(data.list.isNotEmpty()){
        if(i==1){
            newList.clear()
            newList.addAll(data.list)
            adapter1!!.updateData(newList)
        }else if(i>1&&data.next!=-1){
            newList.addAll(data.list)
            adapter1!!.updateData(newList)
        }
    }

}
}